require("uci")

--new uci object
newUci = uci.cursor()

--require a package
luciSys = require "luci.sys"
luciUtil = require "luci.util"
luciJson = require "luci.json"
--[[ 物理接口编号与系统网卡的对应 ]]
interface_to_physical = {"eth0.2", "eth1", "eth0", "eth0"}   --[[interface_to_physical[1] = eth0.2]]--
--[[ 命令的字符串与类型编号的对应 ]]--
cmd_tb = {"connected", "network", "wifi", "hotspot", "reset"}  --[[ cmd_tb[1] = "connected" cmd_tb[2] = "network" ...... ]]--


--[[
通过迭代获得虚拟网口对应的物理网口的编号，设置是根据物理编号填写
如：物理端口1对应eth0.2, 物理端口2对应eth0.1,则find_physical_iface = {"eth0.2", "eth0.1"}
]]--
function find_physical_iface( iface_name )
	local num = 0
	if iface_name then
		for num ,value in pairs(interface_to_physical) do
			if value == iface_name then
				return num
			end
		end
	end
	return 0
end

--[[ 获得数组里面的元素个数 ]]--
function table_var_count( table_name )
	local count = 0
	if table_name then
		for k,v in pairs(table_name) do
			count = count + 1
			end
		end
		return count
end

--[[ 同 luciUtil.trim ]]--
function util_trim_var( value )
	if value == nil then
		return value
	end
	return luciUtil.trim(value)
end

function get_device_infomation()
	local dev_data = {}
	dev_data.mac = luciUtil.exec("ifconfig eth0|grep HWaddr|awk '{print $5}'|sed 's/:/-/g'|tr '[a-f]' '[A-F]'")
	dev_data.mac = util_trim_var(dev_data.mac)
	dev_data.model = luciUtil.exec("uci get system.@system[0].hostname")
	dev_data.model = util_trim_var(dev_data.model)
	dev_data.fm_version = newUci:get("system","device","firmware_revision")
	dev_data.fm_version = util_trim_var(dev_data.fm_version)
	return dev_data
end
--[[ 获取状态信息并组合成ready请求 ]]--
function  get_ready_value()
	local Data = {}
	Data.method = "device.ready"
	local dev_data = get_device_infomation()
	if table_var_count(dev_data) > 0 then
		Data.data = dev_data
	end
	return luciJson.encode(Data) 
end

function  get_reset_value()
	local Data = {}
	Data.method = "device.reset"
	local dev_data = get_device_infomation()
	if table_var_count(dev_data) > 0 then
		Data.data = dev_data
	end
	return luciJson.encode(Data) 
end


--[[ 获取状态信息并且组合成json格式 ]]--
function handle_status_value()
	local Data = {}
	Data.method = "device.report"
	local dev_data = get_device_infomation()
	if table_var_count(dev_data) > 0 then
		Data.data = dev_data
	end

	Data.data.conf = {}
	--[[ network setting ]]--
	local network = {}
	network.gateway = newUci:get("network","lan","gateway")
	network.gateway = util_trim_var(network.gateway)
	network.subnet = newUci:get("network","lan","netmask")
	network.subnet = util_trim_var(network.subnet)
	dhcp_stat = newUci:get("dhcp","lan","ignore")
	if not dhcp_stat then
		network.dhcp = 1
		network.pool_start = newUci:get("dhcp","lan","start")
		network.pool_start = util_trim_var(network.pool_start)
		network.pool_len = newUci:get("dhcp","lan","limit")
		network.pool_len = util_trim_var(network.pool_len)
		network.lease = newUci:get("dhcp","lan","leasetime")
		network.lease = util_trim_var(network.lease)
	else
		network.dhcp = 0
		network.pool_start = ""
		network.pool_len = ""
		network.lease = ""
	end
	network.dns = luciUtil.exec("uci get network.lan.dns|sed 's/ /,/g'")
	network.dns = util_trim_var(network.dns)
	network.up_limit = newUci:get("system","network","uplimit")
	network.up_limit = util_trim_var(network.up_limit)
	network.down_limit = newUci:get("system","network","downlimit")
	network.down_limit = util_trim_var(network.down_limit)

	if table_var_count(network) > 0 then
		Data.data.conf.network = network
	end 

	--[[ hotspot setting ]]-- 
	hotspot={};
	hotspot.nasid = luciUtil.exec("uci get hotspot.@nodogsplash[0].gatewayname")
	hotspot.nasid = util_trim_var(hotspot.nasid)
	hotspot.session_timeout = luciUtil.exec("uci get hotspot.@nodogsplash[0].clientforcetimeout")
	hotspot.session_timeout = util_trim_var(hotspot.session_timeout)
	hotspot.idle_timeout = luciUtil.exec("uci get hotspot.@nodogsplash[0].clientidletimeout")
	hotspot.idle_timeout = util_trim_var(hotspot.idle_timeout)
	hotspot.mac_allow = luciUtil.exec("uci get hotspot.@nodogsplash[0].macallow")
	hotspot.mac_allow = util_trim_var(hotspot.mac_allow)
	hotspot.ip_allow = luciUtil.exec("uci get hotspot.@nodogsplash[0].extipallow")
	hotspot.ip_allow = util_trim_var(hotspot.ip_allow)
	hotspot.domain_allow = luciUtil.exec("uci get hotspot.@nodogsplash[0].domainallow")
	hotspot.domain_allow = util_trim_var(hotspot.domain_allow)
	hotspot.portal = luciUtil.exec("uci get hotspot.@nodogsplash[0].remoteauthenticatoraction")
	hotspot.portal = util_trim_var(hotspot.portal)
	hotspot.up_limit = newUci:get("qosconfig","init","upload")
	hotspot.up_limit = util_trim_var(hotspot.up_limit)
	hotspot.down_limit = newUci:get("qosconfig","init","download")
	hotspot.down_limit = util_trim_var(hotspot.down_limit)
	get_gateway_iface = luciUtil.exec("uci get hotspot.@nodogsplash[0].gateway_interface")
	if string.find(get_gateway_iface, "hslan") then
		get_gateway_iface = "hslan"
		gateway_iface = newUci:get("network", get_gateway_iface, "ifname")
		gateway_iface = util_trim_var(gateway_iface)
	end
	hotspot.ports = {}
	table.insert(hotspot.ports, find_physical_iface(gateway_iface))

	if table_var_count(hotspot) > 0 then
		Data.data.conf.hotspot = hotspot
	end 

	--[[ wifi setting ]]-- 
	Data.data.conf.wifi = {}

	local get_wifi_dev_count = luciUtil.exec("uci show wireless | grep \"wifi-device\" | grep \"config\" | wc -l")
	local wifi_dev_count
	local dev_name_2g = {}
	local dev_name_5g = {}
	local g2 = {}
	local g5 = {}

	if get_wifi_dev_count ~= 0 then
		for wifi_dev_count = 0, get_wifi_dev_count, 1 
			do
				local dev_type = newUci:get("wireless", "radio".. wifi_dev_count, "hwmode")
				if string.find(dev_type, "b") or string.find(dev_type, "g") or string.find(dev_type, "n") then
					table.insert(dev_name_2g, "radio" .. wifi_dev_count)
					channel_width = newUci:get("wireless", "radio" .. wifi_dev_count,"htmode")
					if string.find(channel_width, "40") then
						g2.channel_width = "HT40"
					else
						g2.channel_width = "HT20"
					end
					g2.channel = newUci:get("wireless", "radio" .. wifi_dev_count, "channel")
					g2.channel = util_trim_var(g2.channel);
					g2.txpower = newUci:get("wireless", "radio" .. wifi_dev_count, "txpower")
					g2.txpower = util_trim_var(g2.txpower);
					g2.isolate = newUci:get("wireless", "radio" .. wifi_dev_count, "isolate")
					g2.isolate = util_trim_var(g2.isolate)
					g2.ssids = {}
				end

				if string.find(dev_type, "a") or string.find(dev_type, "c") then
					table.insert(dev_name_5g, "radio" .. wifi_dev_count)
					channel_width = newUci:get("wireless", "radio" .. wifi_dev_count,"htmode")
					if string.find(channel_width, "40") then
						g5.channel_width = "HT40"
					else
						g5.channel_width = "HT20"
					end
					g5.channel = newUci:get("wireless", "radio" .. wifi_dev_count, "channel")
					g5.txpower = newUci:get("wireless", "radio" .. wifi_dev_count, "txpower")
					g5.isolate = newUci:get("wireless", "radio" .. wifi_dev_count, "htmode")
					g5.ssids = {}
				end

				local get_wifi_iface_count = luciUtil.exec("uci show wireless | grep \"wifi-iface\" | grep \"device\" | wc -l")
				local wifi_iface_count
				local get_r_signal= luciUtil.exec("uci get hotspot.@nodogsplash[0].r_signal")
				get_r_signal = util_trim_var(get_r_signal)
				local get_maxassoc= luciUtil.exec("uci get hotspot.@nodogsplash[0].maxassoc")
				get_maxassoc = util_trim_var(get_maxassoc)
				for wifi_iface_count = 0, get_wifi_iface_count - 1, 1
					do
						local ssid_conf = {}
						in_dev = luciUtil.exec("uci get wireless.@wifi-iface[" .. wifi_iface_count .. "].device")
						in_dev = util_trim_var(in_dev)
						ssid_conf.ssid = luciUtil.exec("uci get wireless.@wifi-iface[" .. wifi_iface_count .. "].ssid")
						ssid_conf.ssid = util_trim_var(ssid_conf.ssid)
						ssid_conf.hidden = luciUtil.exec("uci get wireless.@wifi-iface[" .. wifi_iface_count .. "].hidden")
						ssid_conf.hidden = util_trim_var(ssid_conf.hidden)
						ssid_conf.r_signal = get_r_signal
						ssid_conf.maxassoc = get_maxassoc
						ssid_conf.encryption = luciUtil.exec("uci get wireless.@wifi-iface[" .. wifi_iface_count .. "].encryption")
						ssid_conf.encryption = util_trim_var(ssid_conf.encryption)
						ssid_conf.key = luciUtil.exec("uci get wireless.@wifi-iface[" .. wifi_iface_count .. "].key")
						ssid_conf.key = util_trim_var(ssid_conf.key)
						iface_network = luciUtil.exec("uci get wireless.@wifi-iface[" .. wifi_iface_count .. "].network")
						iface_network = util_trim_var(iface_network)
						if iface_network == get_gateway_iface then
								table.insert(Data.data.conf.hotspot.ports, ssid_conf.ssid)
						end

						if string.find(table.concat(dev_name_2g, ":"), in_dev) then
							table.insert(g2.ssids, ssid_conf)
						else
							table.insert(g5.ssids, ssid_conf)
						end
					end
			end
	end

	if table_var_count(g2) > 0 then
		Data.data.conf.wifi.g2 = g2
	end
	if table_var_count(g5) > 0 then
		Data.data.conf.wifi.g5 = g5
	end

	--[[ data setting ]]-- 
	local data={}
	wan_iface = util_trim_var(luciUtil.exec("wan_iface"))
	data.wan_ip = luciUtil.exec("ifconfig " .. wan_iface .. " | awk '/inet addr/{print substr($2,6)}'")
	data.wan_ip = util_trim_var(data.wan_ip)
	data.wan_subnet = luciUtil.exec("ifconfig " .. wan_iface .. " | awk '/inet addr/{print $4}' | awk -F 'Mask:' '{print $2}'")
	data.wan_subnet = util_trim_var(data.wan_subnet)
	data.wan_gateway = luciUtil.exec("route |grep default | awk '{print $2}'")
	data.wan_gateway = util_trim_var(data.wan_gateway)

	get_nds_count = luciUtil.exec("cat /tmp/resolv.conf.auto | grep -v Interface | wc -l")
	data.wan_dns = {}
	for nds_count = get_nds_count, 1, -1 
		do
		dns = luciUtil.exec("cat /tmp/resolv.conf.auto | grep -v Interface | awk '{print $2}'|awk NR==" .. nds_count)
		dns = util_trim_var(dns)
		table.insert(data.wan_dns, dns)
	end

	data.uptime = luciUtil.exec("cat /proc/uptime | awk '{print $1}'")
	data.uptime = util_trim_var(data.uptime)
	data.cpu = luciUtil.exec("uptime | awk '{print $7}' | awk -F',' '{print $1}'")
	data.cpu = util_trim_var(data.cpu)
	data.mem_total = luciUtil.exec("free | grep \"Mem:\" | awk '{print $2}'")
	data.mem_total = util_trim_var(data.mem_total)
	data.mem_usage = luciUtil.exec("free | grep \"Mem:\" | awk '{print $3}'")
	data.mem_usage = util_trim_var(data.mem_usage)
	data.online_all = luciUtil.exec("cat /tmp/dhcp.leases | wc -l")
	data.online_all = util_trim_var(data.online_all)
	data.online_wifi = luciUtil.exec("iw dev wlan0 station dump | grep \"Station\" | wc -l")
	data.online_wifi = util_trim_var(data.online_wifi)
	 if table_var_count(data) > 0 then
		Data.data.conf.data = data
	end

	--print("status =:" .. luciJson.encode(Data));
	return luciJson.encode(Data)
end

--[[ 状态信息 ]]--
--local dev_status_value = handle_status_value()
--print("设备状态：")
--print(dev_status_value)
--[[ ready 请求信息 ]]--
--local ready_request = get_ready_value()
--print("准备请求：")
--print(ready_request)
--[[ reset 请求信息 ]]--
--local  reset_request = get_reset_value()
--print("复位请求：")
--print(reset_request)

--[[
******************************************************************************************************
******************************************************************************************************
******************************************************************************************************

以下为对或得到的数据(Json格式)进行解析以及进行对应的配置

******************************************************************************************************
******************************************************************************************************
******************************************************************************************************
]]--

function find_cmd_type( cmd_string )
	local k, v
	for k, v in pairs(cmd_tb) do
		if v == cmd_string then
			return k
		end
	end
	return 0
end

--[[ 处理network配置(包含：lan配置(network)、LAN口dhcp配置(dhcp)、限速配置(qosconfig) ]]--
function handle_network_config( tab )
	print("in function <<<< handle_network_config >>>> ")
	if tab == nil or table_var_count(tab) == 0 then
		return
	end
	local dhcp_ac = 0
	local dhcp_info = {}
	for k, v in pairs(tab) do
		if v ~= nil then
			if k == "gateway" then
				newUci:set("network", "lan", "gateway", v)
			elseif k == "subnet" then
				newUci:set("network", "lan", "netmask", v)
			elseif k == "dhcp" and v == 1 then
				dhcp_ac = 1
			elseif k == "pool_start" then
				dhcp_info.dhcp_start = v
			elseif k == "pool_len" then
				dhcp_info.dhcp_len = v
			elseif k == "lease" then
				dhcp_info.dhcp_leases = v
			elseif k == "up_limit" then
				newUci:set("qosconfig","init","upload", v)
			elseif k == "down_limit" then
				newUci:set("qosconfig","init","download", v)
			elseif k == "dns" then
				local dns_string
				for c, d in pairs(v) do
					if dns_string == nil then
						dns_string = d
					else
						dns_string = dns_string .. " " .. d
					end
				end
				newUci:set("network", "lan", "dns", dns_string)
			end
		end
	end
	newUci:commit("network")
	newUci:commit("qosconfig")
	if dhcp_ac == 1 then
		newUci:delete("dhcp", "lan", "ignore")
		newUci:set("dhcp", "lan", "start", dhcp_info.dhcp_start)
		newUci:set("dhcp", "lan", "limit", dhcp_info.dhcp_len)
		newUci:set("dhcp", "lan", "leasetime", dhcp_info.dhcp_leases .. "h")
	else 
		newUci:set("dhcp", "lan", "ignore", 1)
	end
	newUci:commit("dhcp")
end
--[[ 处理hotspot相关的参数 ]]--
function handle_hotspot_conf( tab )
	print("in function <<<< handle_hotspot_conf >>>> ")
	if tab == nil or table_var_count(tab) == 0 then
		return
	end
	local n_name
	newUci:foreach("hotspot","nodogsplash",function(s)
		n_name = s[".name"]
	end
	)
	for k, v in pairs(tab) do
		if v ~= nil then
			if k == "domain_allow" then
				newUci:set("hotspot", n_name, "domainallow", v)
			elseif k == "down_limit" then
				newUci:set("hotspot", n_name, "down_limit", v)
			elseif k == "idle_timeout" then
				newUci:set("hotspot", n_name, "idle_timeout", v)
			elseif k == "ip_allow" then
				newUci:set("hotspot", n_name, "ip_allow", v)
			elseif k == "mac_allow" then
				newUci:set("hotspot", n_name, "mac_allow", v)
			elseif k == "nasid" then
				newUci:set("hotspot", n_name, "nasid", v)
			elseif k == "portal" then
				newUci:set("hotspot", n_name, "portal", v)
			elseif k == "session_timeout" then
				newUci:set("hotspot", n_name, "session_timeout", v)
			elseif k == "up_limit" then
				newUci:set("hotspot", n_name, "up_limit", v)
			elseif k == "ports" then
				local ports_str
					for c, d in pairs(v) do
						if ports_str == nil then
						ports_str = d
					else
						ports_str = ports_str .. " " .. d
					end
				end
				newUci:set("hotspot", n_name, "ports", ports_str)
			end
		end
	end
	newUci:commit("hotspot")
end

--[[设置无线iface的配置(SSID, encrypt...) ]]--
function config_set_wireless_iface( tab, dev_name )
	if tab == nil or dev_name == nil then
		return nil
	end
	--[[ 获得ssid配置组的数量(通过获得ssid数组的元素个数) ]]--
	local iface_count = table_var_count(tab)
	if iface_count == 0 then
		return nil
	end
	--[[ 顺序保存 device是dev_name的iface的name(系统中已经存在的) ]]--
	local inface_in_dev = {}
	--[[ 获得当前iface的数量 ]]--
	local get_wifi_iface_count = luciUtil.exec("uci show wireless | grep \"wifi-iface\" | grep \"device\" | wc -l")
	newUci:foreach("wireless","wifi-iface",function(s)
		local t_name = s[".name"]
		local device = newUci:get("wireless", t_name, "device" )
		if device == dev_name then
			table.insert(inface_in_dev, t_name)
		end
	end
	)
	--[[ 对比需要设置的ssid数量和当前设备中的ssid数量 对当前设备中的ssid进行‘多删少增加’ ]]--
	--[[ 并对inface_in_dev进行相应的修改]]--
	if iface_count > table_var_count(inface_in_dev) then
		for i = 1, iface_count - table_var_count(inface_in_dev) do
			local lcname = newUci:add("wireless", "wifi-iface")
			lcname = util_trim_var(lcname)
			if lcname == nil then
				break
			end
			newUci:set("wireless", lcname, "mode", "ap")
			newUci:set("wireless", lcname, "device", dev_name)
			table.insert(inface_in_dev, lcname)
		end
	elseif iface_count < table_var_count(inface_in_dev) then
		for i = table_var_count(inface_in_dev), iface_count + 1, -1 do
			newUci:delete("wireless", inface_in_dev[i])
			table.remove(inface_in_dev, i)
		end
	end

	local set_key = 0
	local key_tmp
	local encrypt_read
	local key_read = 0
	--[[ 循环读取ssids中的table数 i 数字编号， t 对应的table内容 ]]--
	for i, t in pairs(tab) do
		--[[ 解析每个ssid数组中的配置元素 ]]--	
		for k, v in pairs(t) do
			if v ~= nil then
				if k == "ssid" then
					newUci:set("wireless", inface_in_dev[i], "ssid", v)
				elseif k == "network" then
					newUci:set("wireless", inface_in_dev[i], "network", v)
				elseif k == "hidden" then
					newUci:set("wireless", inface_in_dev[i], "hidden", v)
				elseif k ==  "r_signal" then
					newUci:set("wireless", inface_in_dev[i], "r_signal", v)
				elseif k == "maxassoc" then
					newUci:set("wireless", inface_in_dev[i], "maxassoc", v)
				elseif k == "enscription" then 
					if v ~= nil then
						newUci:set("wireless", inface_in_dev[i], "encryption", v)
						if v ~= "none" and v ~= "NONE" then
							set_key = 1
							if key_read == 1 and key_tmp ~= nil then
								newUci:set("wireless", inface_in_dev[i], "key", key_tmp)
							end
						else
							set_key = 0
						end
					end
				elseif k == "key" then
					if encrypt_read == 0 then
						key_tmp = v
						key_read = 1
					else 
						if set_key == 1 then
							newUci:set("wireless", inface_in_dev[i], "key", v)
						end
					end
				end
			end
		end
	end
	newUci:commit("wireless")
end

--[[ 设置无线radios的配置 txpower, channel... ]]--
function set_wireless_config(conf_tb, dev_name )
	if conf_tb == nil or dev_name == nil or table_var_count(conf_tb) == 0 then
		return nil
	end

	for k, v in pairs(conf_tb) do
		if k == "channel" then
			newUci:set("wireless", dev_name, "channel", v)
		elseif k == "channel_width" then
			newUci:set("wireless", dev_name, "htmode", v)
		elseif k == "txpower" then
			newUci:set("wireless", dev_name, "txpower", v)
		elseif k == "ssids" then 
			config_set_wireless_iface(conf_tb.ssids, dev_name)
		end
	end
	newUci:commit("wireless")

end

--[[ 处理无线wifi相关的参数 包括Txpower，channel， interface配置等 ]]--
function handle_wifi_config( tab )
	print("in function <<<< handle_wifi_config >>>> ")

	if tab == nil or table_var_count(tab) <= 0 then
		return
	end

	local g2_dev_num_tb = {}
	local g5_dev_num_tb = {}
	local get_wifi_dev_count = luciUtil.exec("uci show wireless | grep \"wifi-device\" | wc -l")
	local wifi_dev_count

	for wifi_dev_count = 0, get_wifi_dev_count - 1  do
		local dev_type = newUci:get("wireless", "radio".. wifi_dev_count, "hwmode") 
		if string.find(dev_type, "b") or string.find(dev_type, "g") or string.find(dev_type, "n") then
			table.insert(g2_dev_num_tb, "radio" .. wifi_dev_count)
		elseif string.find(dev_type, "a") or string.find(dev_type, "c") then
			table.insert(g5_dev_num_tb, "radio" .. wifi_dev_count)
		end
	end
	local i = 1
	local j = 1
	for k, v in pairs(tab) do
		if k == "g2" then
			set_wireless_config(tab.g2, g2_dev_num_tb[i])
			i = i + 1
		elseif k == "g5" then
			set_wireless_config(tab.g5, g5_dev_num_tb[j])
			j = j + 1
		end
	end
end

--[[ 解析Json格式成table ]]--
function parsing_json_to_table( json_str )
	if json_str == nil then
		print("json_str is nil ")
	else
		print(json_str)
	end

	print("in function <<<< parsing_json_to_table >>>> ")
 	local Data = luciJson.decode(json_str)
 	if Data == nil then 
 		print("Data is nil")
 		return nil
 	end
 	if table_var_count(Data) == 0 then
 	print("no value in Data ")
 		return nil
 	end
 	local cmd_type = find_cmd_type(Data.cmd)
 	print("cmd is " .. Data.cmd ..", type is " .. cmd_type .. ";")
 	if Data.cmd == "wifi" then
 		handle_wifi_config(Data.data)
 		elseif Data.cmd == "hotspot" then
 			handle_hotspot_conf(Data.data)
 		elseif Data.cmd == "network" then
 			handle_network_config(Data.data)
 	end	
 	return 1
 end 
--local wifi_config_str = "{\"cmd\":\"wifi\",\"data\":{\"g2\":{\"channel\":\"auto\",\"channel_width\":\"HT40\",\"isolate\":1,\"ssids\":[{\"ssid\":\"ssid1-2g\",\"hidden\": 0,\"r_signal\":-15,\"maxassoc\":12,\"enscription\":\"none\",\"key\":\"\"},{\"ssid\":\"ssid2-2g\",\"hidden\":0,\"r_signal\":-28,\"maxassoc\":37,\"enscription\":\"none\",\"key\":\"\"}],\"txpower\":28}}}"
--local hotspot_config_str = "{\"cmd\":\"hotspot\",\"data\":{\"domain_allow\":\"asdas\",\"down_limit\":20,\"idle_timeout\":17,\"ip_allow\":\"adas\",\"mac_allow\":\"asdas\",\"nasid\":\"hs10000\",\"portal\": \"http://www.baidu.com\",\"session_timeout\":24,\"up_limit\":35,\"ports\":[\"ssid-5G\",11,19]}}"
--local network_config_str = "  {\"cmd\":\"network\",\"data\":{\"gateway\": \"192.167.1.2\",\"subnet\":\"2.55.255.230\",\"dhcp\":1,\"pool_start\":26,\"pool_len\":53,\"lease\":52,\"dns\":[\"5.55.55.5\", \"114.114.114.114\"],\"up_limit\":3,\"down_limit\":8}}"
--local ret = parsing_json_to_table(wifi_config_str)
--local ret = parsing_json_to_table(network_config_str)
--local ret = parsing_json_to_table(hotspot_config_str)
